import axios from "axios";
export default {
    async get(title) {
        //throw new Error("API demo error")
        // eslint-disable-next-line no-unreachable
        var res;
        await axios.post('/api/dreamhub.papers/_search', {
            from: 0,
            size: 100,
            query: {
                match: {
                    title: title,
                }
            }
        }).then(function (response) {
            res = response
            console.log(response);
        })

        console.log(res)

        return {
            paperList: res.data.hits.hits.map(x=> {
                return {
                    id: x._id,
                    title: x._source.title,
                    authors: x._source.authors,
                    venue: x._source.venue,
                    year:x._source.year,
                    n_citation:x._source.n_citation,
                    page_start:x._source.page_start,
                    page_end:x._source.page_end,
                    lang:x._source.lang,
                    volume:x._source.volume,
                    issue:x._source.issue,
                    url:x._source.url,
                    abstract:x._source.abstract,
                }
            }),
        }
    },

    async getById(id) {
        var res;
        await axios.post('/api/dreamhub.papers/_search', {
            from: 0,
            size: 100,
            query: {
                match: {
                    _id: id,
                }
            }
        }).then(function (response) {
            res = response
            console.log(response);
        })

        console.log(res)

        return {
            paperList: res.data.hits.hits.map(x=> {
                return {
                    id: x._id,
                    title: x._source.title,
                    authors: x._source.authors,
                    venue: x._source.venue,
                    year:x._source.year,
                    n_citation:x._source.n_citation,
                    page_start:x._source.page_start,
                    page_end:x._source.page_end,
                    lang:x._source.lang,
                    volume:x._source.volume,
                    issue:x._source.issue,
                    url:x._source.url,
                    abstract:x._source.abstract,
                }
            }),
        }
    },
    async searchAuthor(keyword) {
        let data = (await axios.post(
            "/api/scholar/author/search/",
            {
                content: keyword,
                field: "name",
                limit: 20,
                offset: 0
            }
        )).data.results;
        console.log(data);
        return data
    }
}
